import axios from 'axios';

const fileId = '7ryM2G71XRVwkQnkklWrbI';
const nodeId = '0:1'; // Page2
const token = process.env.FIGMA_ACCESS_TOKEN;

console.log('🔍 获取节点详细信息...');
console.log('文件ID:', fileId);
console.log('节点ID:', nodeId);

try {
  const response = await axios.get(`https://api.figma.com/v1/files/${fileId}/nodes`, {
    headers: { 'X-Figma-Token': token },
    params: { ids: nodeId }
  });
  
  console.log('✅ 节点数据获取成功!');
  const nodeData = response.data.nodes[nodeId];
  
  if (nodeData && nodeData.document) {
    console.log('节点名称:', nodeData.document.name);
    console.log('节点类型:', nodeData.document.type);
    console.log('子元素数量:', nodeData.document.children?.length || 0);
    
    // 显示前几个子元素
    if (nodeData.document.children) {
      console.log('\n📱 页面内容:');
      nodeData.document.children.slice(0, 5).forEach((child, index) => {
        console.log(`  ${index + 1}. ${child.name} (${child.type})`);
      });
      
      if (nodeData.document.children.length > 5) {
        console.log(`  ... 还有 ${nodeData.document.children.length - 5} 个元素`);
      }
    }
  }
  
  // 保存完整数据到文件
  console.log('\n💾 保存完整数据到 figma-data.json');
  
} catch (error) {
  console.log('❌ 获取失败:', error.response?.status, error.response?.statusText);
  console.log('错误详情:', error.response?.data);
}
